package com.njxxted.activiti.modules.process.extend.controller;

import com.njxxted.activiti.common.response.ResponseVo;
import com.njxxted.activiti.common.util.PageUtil;
import com.njxxted.activiti.modules.base.controller.BaseController;
import com.njxxted.activiti.modules.process.extend.entity.ExtendActCopyEntity;
import com.njxxted.activiti.modules.process.extend.entity.ExtendActInstanceEntity;
import com.njxxted.activiti.modules.process.extend.entity.req.ExtendActInstanceReqEntity;
import com.njxxted.activiti.modules.process.extend.service.ExtendActInstanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 描述：工作流扩展表-流程实例表 exception
 * <p>
 * 作者：HuTongFu
 * 邮箱：hu_tongfu@163.com
 * 时间：2019-08-10 17:14:48
 */
@Api(tags = "流程实例扩展")
@RestController
@RequestMapping("/act/rest/extend/instance")
public class ExtendActInstanceController extends BaseController {

    @Resource
    private ExtendActInstanceService extendActInstanceService;

    @GetMapping(value = "/list/{userId}")
    @ApiOperation(value = "查询我的待办理的流程")
    @ApiImplicitParam(name = "userId", value = "用户id", dataType = "String")
    public ResponseVo getTaskForMeList(@PathVariable String userId,
                                       @RequestParam(defaultValue = "1") int pageNum,
                                       @RequestParam(defaultValue = "10") int pageSize) {
        PageUtil<ExtendActInstanceEntity> list = extendActInstanceService.getTaskForMeList(userId, pageNum, pageSize);
        return ResponseVo.ok(list);
    }

    @ApiOperation(value = "查询我的已办理的流程")
    @GetMapping("/list/done")
    public ResponseVo list(ExtendActInstanceReqEntity param) {
        PageUtil<ExtendActInstanceEntity> extendActProcessInstanceList = extendActInstanceService.queryMyHasBeenDoneList(param);
        return ResponseVo.ok(extendActProcessInstanceList);
    }

    @ApiOperation(value = "查询我已办理的流程各种状态的统计数量")
    @GetMapping("/list/done/count")
    public ResponseVo count(ExtendActInstanceReqEntity param) {
        Map<String, Integer> map = extendActInstanceService.queryMyHasBeenDoneCount(param);
        return ResponseVo.ok(map);
    }


    @GetMapping(value = "/started")
    @ApiOperation(value = "查询我发起的流程")
    public ResponseVo getMyStartedList(ExtendActInstanceReqEntity param) {
        PageUtil<ExtendActInstanceEntity> list = extendActInstanceService.getMyStartedList(param);
        return ResponseVo.ok(list);
    }

    @GetMapping(value = "/draft")
    @ApiOperation(value = "查询我的草稿流程")
    public ResponseVo getMyDraftList(ExtendActInstanceReqEntity param) {
        PageUtil<ExtendActInstanceEntity> list = extendActInstanceService.getMyDraftList(param);
        return ResponseVo.ok(list);
    }

    @GetMapping(value = "/copyed")
    @ApiOperation(value = "查询抄送我的流程")
    public ResponseVo getCopy2MeList(ExtendActInstanceReqEntity param) {
        PageUtil<ExtendActInstanceEntity> list = extendActInstanceService.getCopy2MeList(param);
        return ResponseVo.ok(list);
    }

    @PutMapping(value = "/upd/copy")
    @ApiOperation(value = "更新抄送状态")
    public ResponseVo updCopyStatus(ExtendActCopyEntity param) {
        extendActInstanceService.updCopyStatus(param);
        return ResponseVo.ok();
    }

    @ApiOperation(value = "查询", notes = "根据主键id查询")
    @GetMapping("/info/{id}")
    public ResponseVo info(@PathVariable("id") String id) {
        ExtendActInstanceEntity extendActInstanceEntity = extendActInstanceService.queryObject(id);
        return ResponseVo.ok(extendActInstanceEntity);
    }

    @ApiOperation(value = "查询流程名称下拉框", notes = "查询流程名称下拉框数据")
    @GetMapping("/name/select")
    public ResponseVo getSelectData(ExtendActInstanceReqEntity param) {
        return ResponseVo.ok(extendActInstanceService.getSelectData(param));
    }

    @ApiOperation(value = "根据条件查询流程", notes = "根据条件查询流程")
    @GetMapping("/condition/list")
    public ResponseVo getSelectData(ExtendActInstanceEntity param) {
        return ResponseVo.ok(extendActInstanceService.queryListByBean(param));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public ResponseVo delete(@RequestParam("ids") String[] ids) {
        int i = extendActInstanceService.deleteBatch(ids);
        if (i > 0)
            return ResponseVo.ok();
        else
            return ResponseVo.error();
    }

}
